﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OurFAS.Data;

namespace OurFAS
{
    public partial class FrmMain : Form
    {
        #region 成员变量
        public static Base_Account CurrentUser { get; set; }
        private string m_sCode = null;
        private string m_sDataSource = null;
        #endregion

        #region 构造函数
        public FrmMain()
        {
            InitializeComponent();
        }
        #endregion

        #region 控件函数
        private void FrmMain_Load(object sender, EventArgs e)
        {
            LoadMenu();
            LoadStateInfo();
            LoadTree();

            lblInfo.Visible = false;
            cmbDataSource.SelectedIndex = 0;
        }

        private void InitDataGrid(string type)
        {
            dgvMain.DataSource = null;
            OurFasDBEntities entity = new OurFasDBEntities();
            if (type == "base")
            {
                List<Tbl_BaseAssets> result = entity.Tbl_BaseAssets.ToList();
                if (result.Count() < 1)
                {
                    lblInfo.Visible = true;
                    lblInfo.Text = "没有查询到相关记录！";
                }
                else
                {
                    lblInfo.Visible = false;
                    dgvMain.DataSource = result;
                }
                lblCount.Text = string.Format("共{0}条记录", result.Count());
            }
            else if (type == "self")
            {
                List<Tbl_SelfAssets> result = entity.Tbl_SelfAssets.ToList();
                if (result.Count() < 1)
                {
                    lblInfo.Visible = true;
                    lblInfo.Text = "没有查询到相关记录！";
                }
                else
                {
                    lblInfo.Visible = false;
                    dgvMain.DataSource = result;
                }
                lblCount.Text = string.Format("共{0}条记录", result.Count());
            }
            else if (type == "measure")
            {
                List<Tbl_MeasureAssets> result = entity.Tbl_MeasureAssets.ToList();
                if (result.Count() < 1)
                {
                    lblInfo.Visible = true;
                    lblInfo.Text = "没有查询到相关记录！";
                }
                else
                {
                    lblInfo.Visible = false;
                    dgvMain.DataSource = result;
                }
                lblCount.Text = string.Format("共{0}条记录", result.Count());
            }

            InitDataGridTitle();
        }

        private void InitDataGridTitle()
        {
            int count = dgvMain.ColumnCount;
            for (int i = 0; i < count; i++)
            {
                if (dgvMain.Columns[i].HeaderText == "AssetCode")
                {
                    dgvMain.Columns[i].HeaderText = "资产编号";
                }
                else if (dgvMain.Columns[i].HeaderText == "AssetTagCode")
                {
                    dgvMain.Columns[i].HeaderText = "标签号";
                }
                else if (dgvMain.Columns[i].HeaderText == "AssetName")
                {
                    dgvMain.Columns[i].HeaderText = "资产名称";
                }
                else if (dgvMain.Columns[i].HeaderText == "AssetSpec")
                {
                    dgvMain.Columns[i].HeaderText = "规格型号";
                }
                else if (dgvMain.Columns[i].HeaderText == "TypeCodeL")
                {
                    dgvMain.Columns[i].HeaderText = "大类编码";
                }
                else if (dgvMain.Columns[i].HeaderText == "TypeCodeM")
                {
                    dgvMain.Columns[i].HeaderText = "小类编码";
                }
                else if (dgvMain.Columns[i].HeaderText == "UseFor")
                {
                    dgvMain.Columns[i].HeaderText = "资产用途";
                }
                else if (dgvMain.Columns[i].HeaderText == "InBillCode")
                {
                    dgvMain.Columns[i].HeaderText = "入库单号";
                }
                else if (dgvMain.Columns[i].HeaderText == "ProductionFirm")
                {
                    dgvMain.Columns[i].HeaderText = "生产厂商";
                }
                else if (dgvMain.Columns[i].HeaderText == "OriCost")
                {
                    dgvMain.Columns[i].HeaderText = "资产原值";
                }
                else if (dgvMain.Columns[i].HeaderText == "StartUseDate")
                {
                    dgvMain.Columns[i].HeaderText = "启用日期";
                }
                else if (dgvMain.Columns[i].HeaderText == "InCharge")
                {
                    dgvMain.Columns[i].HeaderText = "负责人";
                }
                else if (dgvMain.Columns[i].HeaderText == "Dept")
                {
                    dgvMain.Columns[i].HeaderText = "所在部门";
                }
                else if (dgvMain.Columns[i].HeaderText == "TaskCode")
                {
                    dgvMain.Columns[i].HeaderText = "课题段代码";
                }
                else if (dgvMain.Columns[i].HeaderText == "GetType")
                {
                    dgvMain.Columns[i].HeaderText = "获取方式";
                }
                else if (dgvMain.Columns[i].HeaderText == "PurchaseFrom")
                {
                    dgvMain.Columns[i].HeaderText = "采购来源";
                }
                else if (dgvMain.Columns[i].HeaderText == "GBCode")
                {
                    dgvMain.Columns[i].HeaderText = "国标编号";
                }
                else if (dgvMain.Columns[i].HeaderText == "MeasureInfo")
                {
                    dgvMain.Columns[i].HeaderText = "计量信息";
                }
                else if (dgvMain.Columns[i].HeaderText == "Location")
                {
                    dgvMain.Columns[i].HeaderText = "具体位置";
                }
                else if (dgvMain.Columns[i].HeaderText == "CertificateNo")
                {
                    dgvMain.Columns[i].HeaderText = "合格证号";
                }
                else if (dgvMain.Columns[i].HeaderText == "RepairDate")
                {
                    dgvMain.Columns[i].HeaderText = "维护日期";
                }
            }
            dgvMain.Refresh();
        }

        private void menuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
            MenuItemClick(menuItem.Text);
        }

        void btn_Click(object sender, EventArgs e)
        {
            ToolStripButton btn = sender as ToolStripButton;
            MenuItemClick(btn.Text);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            lbDate.Text = DateTime.Now.ToLongDateString();
            lbTime.Text = DateTime.Now.ToLongTimeString();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            string keyword = null;
            if (tbKeyword.Text.Trim() != "")
            {
                keyword = tbKeyword.Text;
                dgvMain.DataSource = null;

                if (m_sDataSource == "base")
                {
                    List<Tbl_BaseAssets> result = AssetsHelper.GetBaseAssetsByKeyWords(keyword, null, null, null, null, null, null, 0);
                    if (result.Count() < 1)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text = "没有查询到相关记录！";
                    }
                    else
                    {
                        lblInfo.Visible = false;
                        dgvMain.DataSource = result;
                    }
                    lblCount.Text = string.Format("共{0}条记录", result.Count());
                }
                else if (m_sDataSource == "self")
                {
                    List<Tbl_SelfAssets> result = AssetsHelper.GetSelfAssetsByKeyWords(keyword, null, null, null, null, null, null, 0);
                    if (result.Count() < 1)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text = "没有查询到相关记录！";
                    }
                    else
                    {
                        lblInfo.Visible = false;
                        dgvMain.DataSource = result;
                    }
                    lblCount.Text = string.Format("共{0}条记录", result.Count());
                }
                else if (m_sDataSource == "measure")
                {
                    List<Tbl_MeasureAssets> result = AssetsHelper.GetMeasureAssetsByKeyWords(keyword, null, null, null, null, null, null, 0);
                    if (result.Count() < 1)
                    {
                        lblInfo.Visible = true;
                        lblInfo.Text = "没有查询到相关记录！";
                    }
                    else
                    {
                        lblInfo.Visible = false;
                        dgvMain.DataSource = result;
                    }
                    lblCount.Text = string.Format("共{0}条记录", result.Count());
                }
                InitDataGridTitle();
            }
            else
            {
                MessageBox.Show("关键字不能为空，请输入关键字！");
            }
        }

        private void tvMain_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvMain.SelectedNode == null)
            {
                return;
            }

            //获取选中节点的Tag属性，根据其Tag属性判断采用哪种方式进行查询
            string tvTag = tvMain.SelectedNode.Tag.ToString();
            string tvText = tvMain.SelectedNode.Text.ToString().Trim();
            dgvMain.DataSource = null;
            switch (tvTag)
            {
                case "all":
                    #region List all of the assets in a certain datasource
                    if (m_sDataSource == "base")
                    {
                        List<Tbl_BaseAssets> result = null;

                        result = AssetsHelper.GetBaseAssets();
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "self")
                    {
                        List<Tbl_SelfAssets> result = null;

                        result = AssetsHelper.GetSelfAssets();
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "measure")
                    {
                        List<Tbl_MeasureAssets> result = null;

                        result = AssetsHelper.GetMeasureAssets();
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    break;
                    #endregion
                case "department":
                    #region List the assets belong to a certain department
                    if (m_sDataSource == "base")
                    {
                        List<Tbl_BaseAssets> result = null;
                        result = AssetsHelper.GetBaseAssetsByDepartment(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "self")
                    {
                        List<Tbl_SelfAssets> result = null;
                        result = AssetsHelper.GetSelfAssetsByDepartment(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "measure")
                    {
                        List<Tbl_MeasureAssets> result = null;
                        result = AssetsHelper.GetMeasureAssetsByDepartment(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    break;
                    #endregion
                case "category":
                    #region List the assets belong to a certain category
                    if (m_sDataSource == "base")
                    {
                        List<Tbl_BaseAssets> result = null;
                        result = AssetsHelper.GetBaseAssetsByCategory(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "self")
                    {
                        List<Tbl_SelfAssets> result = null;
                        result = AssetsHelper.GetSelfAssetsByCategory(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "measure")
                    {
                        List<Tbl_MeasureAssets> result = null;
                        result = AssetsHelper.GetMeasureAssetsByCategory(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    break;
                    #endregion
                case "gettype":
                    #region List the assets belong to a certain gettype
                    if (m_sDataSource == "base")
                    {
                        List<Tbl_BaseAssets> result = null;
                        result = AssetsHelper.GetBaseAssetsByGetType(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "self")
                    {
                        List<Tbl_SelfAssets> result = null;
                        result = AssetsHelper.GetSelfAssetsByGetType(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "measure")
                    {
                        List<Tbl_MeasureAssets> result = null;
                        result = AssetsHelper.GetMeasureAssetsByGetType(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    break;
                    #endregion
                case "measureinfo":
                    #region List the assets belong to a certain measureinfo
                    if (m_sDataSource == "base")
                    {
                        List<Tbl_BaseAssets> result = null;
                        result = AssetsHelper.GetBaseAssetsByMeasureInfo(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "self")
                    {
                        List<Tbl_SelfAssets> result = null;
                        result = AssetsHelper.GetSelfAssetsByMeasureInfo(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    else if (m_sDataSource == "measure")
                    {
                        List<Tbl_MeasureAssets> result = null;
                        result = AssetsHelper.GetMeasureAssetsByMeasureInfo(tvText);
                        if (result.Count() < 1)
                        {
                            lblInfo.Visible = true;
                            lblInfo.Text = "没有查询到相关记录！";
                        }
                        else
                        {
                            lblInfo.Visible = false;
                            dgvMain.DataSource = result;
                            lblCount.Text = string.Format("共{0}条记录", result.Count());
                        }
                    }
                    break;
                    #endregion
                default:
                    lblInfo.Visible = true;
                    lblInfo.Text = "没有查询到相关记录！";
                    break;
            }
            InitDataGridTitle();
        }

        private void btnConditionQuery_Click(object sender, EventArgs e)
        {
            MyDataManage.FrmAssetQuery frm = new MyDataManage.FrmAssetQuery();
            frm.ShowDialog();
        }

        private void dgvMain_MouseClick(object sender, MouseEventArgs e)
        {
            m_sCode = dgvMain.CurrentRow.Cells[0].Value.ToString();
        }

        private void cmbDataSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbDataSource.SelectedIndex == 0)
            {
                m_sDataSource = "base";
            }
            else if (cmbDataSource.SelectedIndex == 1)
            {
                m_sDataSource = "self";
            }
            else if (cmbDataSource.SelectedIndex == 2)
            {
                m_sDataSource = "measure";
            }
            InitDataGrid(m_sDataSource);
        }

        private void dgvMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            m_sCode = dgvMain.CurrentRow.Cells[0].Value.ToString();

            MyAssetManage.FrmAssetDetails frm = new MyAssetManage.FrmAssetDetails(EnumHelper.EnumObjctOperateType.View, m_sCode, m_sDataSource);
            frm.ShowDialog();
        }

        #endregion

        #region 私有函数
        private void LoadMenu()
        {
            //初始化菜单栏
            mnuMain.Items.Clear();
            IList<Base_Menu> menuList = DataHelper.GetMenuListByRoleCode(FrmMain.CurrentUser.UserRole);
            IList<Base_Menu> rootMenuList = menuList.Where(c => c.PareMenuCode.Trim() == "00").ToList();
            foreach (Base_Menu rootMenu in rootMenuList)
            {
                IList<Base_Menu> subMenuList = menuList
                    .Where(c => c.PareMenuCode.Trim() == rootMenu.MenuCode.Trim()).ToList();
                ToolStripMenuItem rootMenuItem = new ToolStripMenuItem();
                rootMenuItem.Text = rootMenu.MenuTitle.Trim();
                foreach (Base_Menu subMenu in subMenuList)
                {
                    if (subMenu.MenuTitle == "分割线")
                    {
                        ToolStripSeparator separator = new ToolStripSeparator();
                        rootMenuItem.DropDownItems.Add(separator);
                    }
                    else
                    {

                        ToolStripMenuItem subMenuItem = new ToolStripMenuItem();
                        subMenuItem.Image = (System.Drawing.Bitmap)OurFAS.Properties.Resources.ResourceManager.GetObject(subMenu.MenuTitle.Trim());
                        subMenuItem.Text = subMenu.MenuTitle.Trim();
                        subMenuItem.Click += new EventHandler(menuItem_Click);

                        rootMenuItem.DropDownItems.Add(subMenuItem);

                        if (subMenu.IsInBar == true)
                        {
                            ToolStripButton btn = new ToolStripButton();
                            btn.Image = (System.Drawing.Bitmap)OurFAS.Properties.Resources.ResourceManager.GetObject(subMenu.MenuTitle.Trim());
                            btn.ImageScaling = ToolStripItemImageScaling.None;
                            btn.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
                            btn.Text = subMenu.MenuTitle.Trim();
                            btn.Click += new EventHandler(btn_Click);
                            tsMain.Items.Add(btn);
                        }
                    }
                }
                mnuMain.Items.Add(rootMenuItem);
            }
        }

        private void LoadTree()
        {
            tvMain.Nodes.Clear();

            //初始化根节点
            TreeNode rootNode = new TreeNode();
            rootNode.Text = "全部资产";
            rootNode.Tag = "all";
           
            tvMain.Nodes.Add(rootNode);

            //根据类别分类
            TreeNode departmentNode = new TreeNode();
            departmentNode.Text = "部门分类";
            departmentNode.Tag = "all";
          
            rootNode.Nodes.Add(departmentNode);

            IList<Dict_Dept> departmentList = null;
            departmentList = AssetsHelper.GetDepartments();
            if (departmentList == null)
            {
                return;
            }
            foreach (Dict_Dept department in departmentList)
            {
                TreeNode node = new TreeNode();
                node.Text = department.Dept;
                node.Tag = "department";
                departmentNode.Nodes.Add(node);
            }

            //按照设备分类
            TreeNode categoryNode = new TreeNode();
            categoryNode.Text = "设备分类";
            categoryNode.Tag = "all";
            rootNode.Nodes.Add(categoryNode);

            IList<Dict_Category> categoryList = null;
            categoryList = AssetsHelper.GetCategorys();
            if (categoryList == null)
            {
                return;
            }
            foreach (Dict_Category category in categoryList)
            {
                TreeNode node = new TreeNode();
                node.Text = category.Category;
                node.Tag = "category";
                categoryNode.Nodes.Add(node);
            }

            //根据获取方式分类
            TreeNode gettypeNode = new TreeNode();
            gettypeNode.Text = "获取方式分类";
            gettypeNode.Tag = "all";
            rootNode.Nodes.Add(gettypeNode);

            IList<Dict_GetType> gettypeList = null;
            gettypeList = AssetsHelper.GetGetTypes();
            if (gettypeList == null)
            {
                return;
            }
            foreach (Dict_GetType gettype in gettypeList)
            {
                TreeNode node = new TreeNode();
                node.Text = gettype.GetType;
                node.Tag = "gettype";
                gettypeNode.Nodes.Add(node);
            }

            //根据计量信息分类
            TreeNode measureNode = new TreeNode();
            measureNode.Text = "计量信息分类";
            measureNode.Tag = "all";
            rootNode.Nodes.Add(measureNode);

            IList<Dict_MeasureInfo> measureList = null;
            measureList = AssetsHelper.GetMeasureInfos();
            if (measureList == null)
            {
                return;
            }
            foreach (Dict_MeasureInfo measure in measureList)
            {
                TreeNode node = new TreeNode();
                node.Text = measure.MeasureInfo;
                node.Tag = "measureinfo";
                measureNode.Nodes.Add(node);
            }
            rootNode.ExpandAll();
        }

        private void LoadStateInfo()
        {
            tslInfo.Text = string.Format("当前用户:{0}", FrmMain.CurrentUser.UserName);
        }

        private void MenuItemClick(string sTitle)
        {
            switch (sTitle)
            {
                #region 系统
                //重新登录
                case "重新登录":
                    if (MessageBox.Show("您确定要退出，更换其他账号登录吗？", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        Application.Restart();
                    }
                    break;
                //修改密码
                case "修改密码":
                    {
                        MySystem.FrmChangePwd window = new MySystem.FrmChangePwd();
                        window.ShowDialog();
                    }
                    break;
                //账户管理
                case "账户管理":
                    {
                        MySystem.FrmAccount window = new MySystem.FrmAccount();
                        window.ShowDialog();
                    }
                    break;
                //账户管理
                case "角色管理":
                    {
                        MySystem.FrmRole window = new MySystem.FrmRole();
                        window.ShowDialog();
                    }
                    break;
                #endregion

                #region 资产管理
                case "资产盘点":
                    {
                        MyAssetManage.FrmAssetCount frm = new MyAssetManage.FrmAssetCount();
                        frm.ShowDialog();
                    }
                    break;
                case "新增资产":
                    {
                        MyAssetManage.FrmAssetDetails frm = new MyAssetManage.FrmAssetDetails(EnumHelper.EnumObjctOperateType.New, null, m_sDataSource);
                        frm.ShowDialog();
                    }
                    break;
                case "编辑资产":
                    {
                        if (string.IsNullOrEmpty(m_sCode))
                        {
                            MessageBox.Show("请首先选择一条要查看的资产记录！");
                        }
                        else
                        {
                            MyAssetManage.FrmAssetDetails frm = new MyAssetManage.FrmAssetDetails(EnumHelper.EnumObjctOperateType.Edit, m_sCode, m_sDataSource);
                            frm.ShowDialog();
                        }
                    }
                    break;
                case "删除资产":
                    {
                        if (string.IsNullOrEmpty(m_sCode))
                        {
                            MessageBox.Show("请首先选择一条要查看的资产记录！");
                        }
                        else
                        {
                            MyAssetManage.FrmAssetDetails frm = new MyAssetManage.FrmAssetDetails(EnumHelper.EnumObjctOperateType.Delete, m_sCode, m_sDataSource);
                            frm.ShowDialog();
                        }
                    }
                    break;
                case "设备借出归还":
                    {
                        if (string.IsNullOrEmpty(m_sCode))
                        {
                            MessageBox.Show("请首先选择一条待借出的资产记录！");
                        }
                        else
                        {
                            MyAssetManage.FrmBorrow frm = new MyAssetManage.FrmBorrow(m_sCode, m_sDataSource);
                            frm.ShowDialog();
                        }
                    }
                    break;
                case "设备维修":
                    {
                        if (string.IsNullOrEmpty(m_sCode))
                        {
                            MessageBox.Show("请首先选择一条待维修的资产记录！");
                        }
                        else
                        {
                            MyAssetManage.FrmRepair frm = new MyAssetManage.FrmRepair(m_sCode, m_sDataSource);
                            frm.ShowDialog();
                        }
                    }
                    break;
                case "条码打印":
                    {
                        if (string.IsNullOrEmpty(m_sCode))
                        {
                            MessageBox.Show("请首先选择一条要查看的资产记录！");
                        }
                        else
                        {
                            OurFasDBEntities entity = new OurFasDBEntities();
                            if (m_sDataSource == "base")
                            {
                                Tbl_BaseAssets record = entity.Tbl_BaseAssets.Where(c => c.AssetCode.Trim() == m_sCode).FirstOrDefault();
                                MyReport.ReportHelper.PrintBaseAssetBarCode(record);
                   
                            }
                            else if (m_sDataSource == "self")
                            {
                                Tbl_SelfAssets record = entity.Tbl_SelfAssets.Where(c => c.AssetCode.Trim() == m_sCode).FirstOrDefault();
                                MyReport.ReportHelper.PrintSelfAssetBarCode(record);
                            }
                            else if (m_sDataSource == "measure")
                            {
                                Tbl_MeasureAssets record = entity.Tbl_MeasureAssets.Where(c => c.AssetCode.Trim() == m_sCode).FirstOrDefault();
                                MyReport.ReportHelper.PrintMeasureAssetBarCode(record);
                            }
                        }
                    }
                    break;
                #endregion

                #region 数据维护
                case "设备查询":
                    {
                        MyDataManage.FrmAssetQuery frm = new MyDataManage.FrmAssetQuery();
                        frm.ShowDialog();
                    }
                    break;
                case "数据导入":
                    {
                        MyDataManage.FrmDataInput frm = new MyDataManage.FrmDataInput();
                        frm.ShowDialog();
                    }
                    break;
                case "数据导出":
                    {
                        MyDataManage.FrmDataOutput frm = new MyDataManage.FrmDataOutput();
                        frm.ShowDialog();
                    }
                    break;
                case "数据清理":
                    {
                        if (MessageBox.Show("您确定要对主资产表进行数据清理吗？", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            OurFasDBEntities entity = new OurFasDBEntities();
                            foreach (Tbl_BaseAssets asset in entity.Tbl_BaseAssets.ToList())
                            {
                                entity.Tbl_BaseAssets.DeleteObject(asset);
                            }
                            try
                            {
                                entity.SaveChanges();
                                MessageBox.Show("已完成对主资产表的数据清理操作！");
                            }
                            catch
                            {
                                MessageBox.Show("在对主资产表进行数据清理操作时出错，请重试或联系管理员！");
                                return;
                            }
                        }
                    }
                    break;
                #endregion

                #region 资产台账
                case "总资产台账":
                    {
                    }
                    break;
                case "部门资产台账":
                    {
                    }
                    break;
                #endregion

                #region 辅助工具
                case "记事本":
                    {
                        System.Diagnostics.Process.Start("notepad.exe");
                    }
                    break;
                case "计算器":
                    {
                        System.Diagnostics.Process.Start("calc.exe");
                    }
                    break;
                #endregion

                #region 帮助
                case "关于":
                    {
                    }
                    break;
                #endregion

                default:
                    break;
            }
        }

        #endregion
    }
}
